<template>
  <div class="app-container">
    <router-link to="createNotice">
      <div v-permission="['notice:create']" class="addbtn">创建公告</div>
    </router-link>
    <div class="seatch">
      <el-input
        v-model="listQuery.keyword"
        placeholder="按名称搜索"
        @keyup.enter.native="searchName($event)"
      >
        <i slot="prefix" class="el-input__icon el-icon-search" @click="getList()" />
      </el-input>
    </div>
    <div class="content">
      <el-table
        v-loading="listLoading"
        align="center"
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column
          prop="title"
          align="center"
          label="公告标题"
        />
        <el-table-column
          align="center"
          label="同步APP"
        >
          <template slot-scope="{row}">
            {{ row.toApp?'是':'否' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createAt"
          align="center"
          label="创建时间"
        />
        <el-table-column
          align="center"
          prop="createAt"
          label="操作"
          width="220"
        >
          <template slot-scope="{row}">
            <div class="operate">
              <div>
                <router-link :to="{ path: 'detailNotice', query: { id: row.id }}">详情</router-link>
              </div>
              <div v-permission="['notice:eidt']">
                <router-link :to="{ path: 'edgeNotice', query: { id: row.id }}">编辑</router-link>
              </div>
              <div v-permission="['notice:delete']" @click="deleteDialog(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageination-div">
        <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
      </div>
    </div>

    <delete-dialog
      :dislog-name="deleteObiect.title"
      :dialog-del-visible="dialogDelVisible"
      :title="'公告'"
      @funcancl="funcancl"
      @func="deleteData"
    />
  </div>
</template>

<script>
import Pagination from '@/components/pagination'
import DeleteDialog from '@/components/dialog/delete'
import { noticeList, deleteNotice } from '@/api/notice'
export default {
  name: 'Notice',
  components: {
    Pagination,
    DeleteDialog
  },
  data() {
    return {
      tableData: [],
      detailData: {},
      total: 0,
      listLoading: true,
      listQuery: {
        keyword: null,
        pageNum: 1,
        pageSize: 10
      },
      diaDelOrAdd: false,
      dialogDelVisible: false,
      addForm: {
        name: '',
        type: '',
        num: '',
        entryDate: '',
        outDate: '',
        holder: '',
        dataTime: []
      },
      deleteObiect: {},
      rules: {
        // name: [
        //   { required: true, message: '必填', trigger: 'change' }
        // ]
      }
    }
  },
  computed: {

  },
  mounted() {
    this.getList()
  },
  methods: {
    sizeChange(val) {
      this.pageNum = val
    },
    currentChange(val) {
      this.currentPage = val
    },
    searchName(e) {
      this.listQuery.keyword = e.target.value
      this.getList()
    },

    funcancl(val) {
      this.dialogDelVisible = false
    },
    funsetcancl(val) {
      this.dialogResetVisible = false
    },
    // 获取数据
    async getList() {
      const res = await noticeList(this.listQuery)
      if (res.code === 200) {
        this.tableData = res.data.list
        this.total = res.data.total || 0
        this.pages = res.data.pages || 0
        this.listLoading = false
      }
    },
    // 删除
    deleteDialog(row) {
      this.dialogDelVisible = true
      this.deleteObiect = row
    },
    async deleteData() {
      const id = this.deleteObiect.id
      const res = await deleteNotice(id)
      if (res.code === 200) {
        this.getList()
        this.dialogDelVisible = false
        this.$message({
          type: 'success',
          message: '删除成功!',
          showClose: true,
          center: true,
          duration: 2 * 1000
        })
      } else {
        this.dialogDelVisible = false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.app-container{
  .textName{
    font-size:14px;
    font-weight:400;
    color:rgba(247,181,0,0.8);
    span{
      font-size:14px;
      font-weight:400;
      color:rgba(255,255,255,0.8);
    }
  }
}
</style>
